<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>随便打TCS系统</title>
<!-- Bootstrap -->
<link href="<%=basePath%>vendors/bootstrap/dist/css/bootstrap.min.css"
	rel="stylesheet">
<!-- Font Awesome -->
<link
	href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
	rel="stylesheet">
<!-- Select2 -->
<link href="<%=basePath%>vendors/select2/dist/css/select2.min.css"
	rel="stylesheet">
<!-- NProgress -->
<link href="<%=basePath%>vendors/nprogress/nprogress.css"
	rel="stylesheet">
<!-- iCheck -->
<link href="<%=basePath%>vendors/iCheck/skins/flat/green.css"
	rel="stylesheet">

<!-- bootstrap-progressbar -->
<link
	href="<%=basePath%>vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css"
	rel="stylesheet">
<!-- JQVMap -->
<link href="<%=basePath%>vendors/jqvmap/dist/jqvmap.min.css"
	rel="stylesheet" />
<!-- bootstrap-daterangepicker -->
<link
	href="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.css"
	rel="stylesheet">

<!-- Custom Theme Style -->
<link href="<%=basePath%>build/css/custom.min.css" rel="stylesheet">

<!-- 富文本  -->
<link href="<%=basePath%>static/css/quill.snow.css" rel="stylesheet">
	<style>
		.inputBox input{margin-top:10px;}
	</style>
</head>

<body class="nav-md">
	<div class="container body">
		<div class="main_container">
			<div class="col-md-3 left_col">
				<div class="left_col scroll-view">
					<div class="clearfix"></div>
					<br />
				</div>
			</div>

			<!-- page content -->
			<div class="right_col" role="main">
				<div class="">
					<div class="page-title">
						<div class="title_left">
							<h3>商城商品</h3>
						</div>


					</div>
					<div class="clearfix"></div>

					<div class="row">
						<div class="col-md-12 col-sm-12 col-xs-12">
							<div class="x_panel">
								<div class="x_title">
									<h2>创建一个新的文章</h2>

									<div class="clearfix"></div>
								</div>
								<div class="x_content">
									<form name="myForm" class="form-horizontal form-label-left"
										novalidate method="post" enctype="multipart/form-data"
										id="formUpload">

										<p>
											您需要将以下内容填写完整后才可以创建模块，如有疑问请
											<code>联系客服</code>
											以帮助您完成相关配置以及信息完善
										</p>
										<span class="section">基本信息</span>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">标题 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input id="title" class="form-control col-md-7 col-xs-12"
													name="title" placeholder="请输入文字" required="required"
													type="text" value="">
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">分类<span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<select class="form-control" id="classifyid">
													<c:forEach items="${companyClassifies}" var="s" varStatus="z">
														<option value="${s.id}">${s.classify}</option>
													</c:forEach>
												</select>
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">导读<span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input id="introduction" class="form-control col-md-7 col-xs-12"
													name="introduction" placeholder="" required="required"
													type="text" value="">
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">营销效果<span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<div class="inputBox yxBox">
													<input id="derate" class="form-control col-md-7 col-xs-12"
														   name="derate" placeholder="" required="required"
														   type="text" value="">
												</div>
												<!-- 增删按钮-->
												<a type="button" class="btn btn-default xc_add_btn" href="javascript:void(0)"
												   onclick="addBtn(this)">添加</a>
												<a type="button" class="btn btn-default xc_reduce_btn" href="javascript:void(0)"
												   onclick="reduceBtn(this)">删除</a>
											</div>
										</div>
                                        <div class="item form-group">
                                            <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                                   for="name">活动现场<span class="required">*</span>
                                            </label>
                                            <div class="col-md-6 col-sm-6 col-xs-12">
                                                <input class="form-control col-md-7 col-xs-12" id="activity"
                                                       name="activity" required="required" type="file"
                                                       class="img-input" multiple="multiple"
                                                       placeholder="请先上传图片" form="formUpload">
                                            </div>
                                        </div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">引流方案(实操步骤)<span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<div class="inputBox ylBox">
													<input id="yl" class="form-control col-md-7 col-xs-12"
														   name="yl" placeholder="请输入文字" required="required"
														   type="text" value="">
												</div>
												<!-- 增删按钮-->
												<a type="button" class="btn btn-default xc_add_btn" href="javascript:void(0)"
												   onclick="addBtn(this)">添加</a>
												<a type="button" class="btn btn-default xc_reduce_btn" href="javascript:void(0)"
												   onclick="reduceBtn(this)">删除</a>
											</div>
										</div>
                                        <div class="item form-group">
                                            <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                                   for="name">截流方案(实操步骤)<span class="required">*</span>
                                            </label>
                                            <div class="col-md-6 col-sm-6 col-xs-12">
                                                <div class="inputBox jlBox">
                                                    <input id="jl" class="form-control col-md-7 col-xs-12"
                                                           name="jl" placeholder="请输入文字" required="required"
                                                           type="text" value="">
                                                </div>
                                                <!-- 增删按钮-->
                                                <a type="button" class="btn btn-default xc_add_btn" href="javascript:void(0)"
                                                   onclick="addBtn(this)">添加</a>
                                                <a type="button" class="btn btn-default xc_reduce_btn" href="javascript:void(0)"
                                                   onclick="reduceBtn(this)">删除</a>
                                            </div>
                                        </div>
                                        <div class="item form-group">
                                            <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                                   for="name">回流方案(实操步骤)<span class="required">*</span>
                                            </label>
                                            <div class="col-md-6 col-sm-6 col-xs-12">
                                                <div class="inputBox hlBox">
                                                    <input id="hl" class="form-control col-md-7 col-xs-12"
                                                           name="hl" placeholder="请输入文字" required="required"
                                                           type="text" value="">
                                                </div>
                                                <!-- 增删按钮-->
                                                <a type="button" class="btn btn-default xc_add_btn" href="javascript:void(0)"
                                                   onclick="addBtn(this)">添加</a>
                                                <a type="button" class="btn btn-default xc_reduce_btn" href="javascript:void(0)"
                                                   onclick="reduceBtn(this)">删除</a>
                                            </div>
                                        </div>
										<div class="item form-group" id="pic1">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">相关物料(宣传单)<span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input class="form-control col-md-7 col-xs-12" id="propagate"
													name="propagate" required="required" type="file"
                                                    class="img-input" multiple="multiple"
													placeholder="请先上传图片" form="formUpload">
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												   for="name">相关物料(礼品展架)<span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input class="form-control col-md-7 col-xs-12" id="gift"
													   name="gift" required="required" type="file"
													   class="img-input" multiple="multiple"
													   placeholder="请先上传图片" form="formUpload">
											</div>
										</div>
										<div class="ln_solid"></div>
										<div class="form-group">
											<div class="col-md-6 col-md-offset-3">
												<a type="submit" class="btn btn-primary"
													href="javascript:void(0)"
													onclick="history.back(-1);">取消</a> <input
													id="add" type="button" class="btn btn-success"
													href="javascript:void(0)" value="发布">

											</div>
										</div>
									</form>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<!-- 富文本 -->
			<script src="<%=basePath%>static/js/katex.min.js"></script>
	        <script src="<%=basePath%>static/js/highlight.min.js"></script>
	        <script src="<%=basePath%>static/js/quill.js"></script>
			<script src="<%=basePath%>static/js/quill.min.js"></script>
	        <!-- Initialize Quill editor -->
	        <script src="<%=basePath%>static/js/jquery-1.7.1.min.js"></script>
			<script src="<%=basePath%>static/js/image-file-visible.js"></script>
	        <script>
	        var quill = new Quill('#editor-container', {
			    modules: {
			      formula: true,
			      syntax: true,
			      toolbar: '#toolbar-container'
			    },
			    placeholder: '请输入内容',
			    theme: 'snow'
			  });
	        </script>
	        
			<!-- 上传图片并添加-->
			<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
			<script type="text/javascript">
			$('#add').click(function () {
				// 上传文件
				var activity = document.getElementById("activity").files;
				var activities = [];
				for (var i = 0; i < activity.length; i++){
                    activities.push(addfile(activity[i]));
				}

				var propagate = document.getElementById("propagate").files;
				var propagates = [];
				for (var i = 0; i < propagate.length; i++){
					propagates.push(addfile(propagate[i]));
				}

				var gift = document.getElementById("gift").files;
				var gifts = [];
				for (var i = 0; i < gift.length; i++){
					gifts.push(addfile(gift[i]));
				}

                console.log(propagates);
				console.log(gifts);

				ajaxPost(activities, propagates, gifts);
			});		

			function addfile(file) {
				var fm = new FormData();
				fm.append('file', file);
				console.log(file);
				$.ajax({
					url: "<%=basePath%>layfile/uploadFile1",
					type : 'POST',
					data : fm,
					async : false,
					contentType : false, //禁止设置请求类型
					processData : false, //禁止jquery对DAta数据的处理,默认会处理
					//禁止的原因是,FormData已经帮我们做了处理
					success : function(result) {
						file = result.json;
					}
				});
				return file;
			}
		    </script>

			<script type="text/javascript">
				// ajax 对象
				function ajaxObject() {
					var xmlHttp;
					try {
						// Firefox, Opera 8.0+, Safari
						xmlHttp = new XMLHttpRequest();
					} catch (e) {
						// Internet Explorer
						try {
							xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
						} catch (e) {
							try {
								xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
							} catch (e) {
								alert("您的浏览器不支持AJAX！");
								return false;
							}
						}
					}
					return xmlHttp;
				}
			
			
				// ajax post请求：
				function ajaxPost(activities, propagates, gifts) {
					var yxAll = [];  //营销
					var ylAll = [];
					var jlAll = [];
					var hlAll = [];
					//根据类名来遍历每块区域的input值
					$(".yxBox input").each(function () {
						yxAll.push(this.value)
					});
					$(".ylBox input").each(function () {
						ylAll.push(this.value)
					});
					$(".jlBox input").each(function () {
						jlAll.push(this.value)
					});
					$(".hlBox input").each(function () {
						hlAll.push(this.value)
					});

					var title = $("#title").val();
					var introduction = $("#introduction").val();
					var classifyid = $("#classifyid").find("option:selected").val();
					var ajax = ajaxObject();
					ajax.open("post", "insertCompanyArticle?title=" + title +
							"&introduction=" + introduction +
							"&classifyid=" + classifyid +
							"&yxAll=" + yxAll +
							"&ylAll=" + ylAll +
							"&jlAll=" + jlAll +
							"&hlAll=" + hlAll +
							"&activities=" + activities +
							"&propagates=" + propagates +
							"&gifts=" + gifts, true);
					ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					ajax.onreadystatechange = function() {
						if (ajax.readyState == 4) {
							if (ajax.status == 200) {
								var result = ajax.responseText;
								if (result == "success") {
									//请求成功
									alert("添加成功");
									location.href = "companyArticleIndex";
								} else {
									//创建失败
									alert(result);
								}
							} else if (ajax.status == 0) {
								//请求失败
								alert("您使用的火狐浏览器不支持本次操作，请更换浏览器重试");
							}else {
							//请求失败
							alert("请求终止，请检查操作或联系客服咨询" + ajax.status);
						}
						} else {
						}
					};
					ajax.send();
			
				}
			</script>
		</div>
	</div>
	<script>
		//添加按钮
		function addBtn(e){
			var box = $(e).siblings(".inputBox");
			if(box.find("input").length<10){
				box.append('<input id="derate" class="form-control col-md-7 col-xs-12" name="derate" required="required" type="text" value="">');
			}
		}
		//删除按钮
		function reduceBtn(e){
			var box = $(e).siblings(".inputBox");
			if(box.find("input").length>1){
				box.children("input:last").remove();
			}
		}
	</script>
	<!-- jQuery -->
	<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
	<!-- Bootstrap -->
	<script src="<%=basePath%>vendors/bootstrap/dist/js/bootstrap.min.js"></script>
	<!-- FastClick -->
	<script src="<%=basePath%>vendors/fastclick/lib/fastclick.js"></script>
	<!-- NProgress -->
	<script src="<%=basePath%>vendors/nprogress/nprogress.js"></script>
	<!-- bootstrap-daterangepicker -->
	<script src="<%=basePath%>vendors/moment/min/moment.min.js"></script>
	<script
		src="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.js"></script>
	<!-- Chart.js -->
	<script src="<%=basePath%>vendors/Chart.js/dist/Chart.min.js"></script>
	<!-- validator -->
	<script src="<%=basePath%>vendors/validator/validator.js"></script>
	<!-- Custom Theme Scripts -->
	<script src="<%=basePath%>build/js/custom.min.js"></script>
	<!-- Select2 -->
	<script src="<%=basePath%>vendors/select2/dist/js/select2.full.min.js"></script>
</body>
</html>